﻿/// <summary>
/// 时间：2020.4.23
/// 作用：控制CharacterController处理来自于InputControl的输入
/// 更新：NULL
/// </summary>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace CommonLib
{
	public class RoleControl : MonoBehaviour
	{
		[SerializeField]
		Rigidbody2D rb;
		[SerializeField]
		InputControl input;

		float horizenInput;
		float verticalInput;

		[SerializeField]
		protected float moveSpeed;

		[SerializeField]
		float upSpeed;
		[SerializeField]
		float rightSpeed;
		protected virtual void Update()
		{
			horizenInput = Input.GetAxis("Horizontal");
			verticalInput = Input.GetAxis("Vertical");
		}
		protected virtual void FixedUpdate()
		{
			upSpeed = verticalInput > 0 ? moveSpeed * Mathf.Abs(verticalInput) : -moveSpeed * Mathf.Abs(verticalInput);
			rightSpeed = horizenInput > 0 ? moveSpeed * Mathf.Abs(horizenInput) : -moveSpeed * Mathf.Abs(horizenInput);
			rb.velocity = new Vector3(rightSpeed, upSpeed, 0);
		}

		private void Awake()
		{
			rb = GetComponent<Rigidbody2D>();
			input = GetComponent<InputControl>();
		}
	}

	public class RoleKey {
		public const string K_Up = "w";
		public const string K_Down = "s";
		public const string K_Right = "d";
		public const string K_Left = "a";
	}
}